package wrapper;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.StringTokenizer;

import vlms.bean.IssuedMovie;
import vlms.bean.Movie;
import vlms.bean.Person;
import vlms.bean.PremiumCustomer;

public class MovieIssue {
	private int movieid;
	private String moviename;
	private String moviebanner;
	private Date releasedate;
	private float rentamount;
	private String category;
	private int copiesavailable;

	private int issueid;
	private Date duedate;
	private int personid;
	private Date issuedate;
	private String issuedstatus;
	
	public int getMovieid() {
		return movieid;
	}
	public void setMovieid(int movieid) {
		this.movieid = movieid;
	}
	public String getMoviename() {
		return moviename;
	}
	public void setMoviename(String moviename) {
		this.moviename = moviename;
	}
	public String getMoviebanner() {
		return moviebanner;
	}
	public void setMoviebanner(String moviebanner) {
		this.moviebanner = moviebanner;
	}
	public Date getReleasedate() {
		return releasedate;
	}
	public void setReleasedate(Date releasedate) {
		this.releasedate = releasedate;
	}
	public float getRentamount() {
		return rentamount;
	}
	public void setRentamount(float rentamount) {
		this.rentamount = rentamount;
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public int getCopiesavailable() {
		return copiesavailable;
	}
	public void setCopiesavailable(int copiesavailable) {
		this.copiesavailable = copiesavailable;
	}
	public int getIssueid() {
		return issueid;
	}
	public void setIssueid(int issueid) {
		this.issueid = issueid;
	}
	public Date getDuedate() {
		return duedate;
	}
	public void setDuedate(Date duedate) {
		this.duedate = duedate;
	}
	public int getPersonid() {
		return personid;
	}
	public void setPersonid(int personid) {
		this.personid = personid;
	}
	public Date getIssuedate() {
		return issuedate;
	}
	public void setIssuedate(Date issuedate) {
		this.issuedate = issuedate;
	}
	public String getIssuedstatus() {
		return issuedstatus;
	}
	public void setIssuedstatus(String issuedstatus) {
		this.issuedstatus = issuedstatus;
	}
	
	public static MovieIssue convertToMovieIssue(String input) throws Exception
	{
		MovieIssue mi = new MovieIssue();
		
		StringTokenizer str = new StringTokenizer(input, ":#");
		
		if (str.countTokens() != 12)
		{
			mi.movieid = Integer.parseInt(str.nextToken());
			mi.moviename = str.nextToken();
			mi.moviebanner = str.nextToken();
			mi.releasedate  = new SimpleDateFormat("yyyy-mm-dd").parse(str.
								  nextToken());
			mi.rentamount = Float.parseFloat(str.nextToken());
			mi.category = str.nextToken();;
			mi.copiesavailable = Integer.parseInt(str.nextToken());

			mi.issueid = Integer.parseInt(str.nextToken());
			mi.duedate = new SimpleDateFormat("yyyy-mm-dd").parse(str.
					     nextToken());;
			mi.personid = Integer.parseInt(str.nextToken());
			mi.issuedate = new SimpleDateFormat("yyyy-mm-dd").parse(str.
					  nextToken());
			mi.issuedstatus= str.nextToken();
		}
		else
		{
			throw new Exception("Invalid string provided for populating the " +
								"wrapper.");
		}
		return mi;
	}
	
	public static MovieIssue mixObjects(Movie movie, IssuedMovie im)
	{
		MovieIssue mi  = new MovieIssue();
		mi.movieid = movie.getMovieid();
		mi.moviename = movie.getMoviename();
		mi.moviebanner = movie.getMoviebanner();
		mi.releasedate  = movie.getReleasedate();
		mi.rentamount = movie.getRentamount();
		mi.category = movie.getCategory();
		mi.copiesavailable = movie.getCopiesavailable();

		mi.issueid = im.getIssueid();
		mi.duedate = im.getDuedate();
		mi.personid = im.getPersonid();
		mi.issuedate = im.getIssuedate();
		mi.issuedstatus= im.getIssuedstatus();
		return mi;
	}
	public static MovieIssue[] mixObjects(Movie[] movie,IssuedMovie[] im) 
	{
		MovieIssue mi[]; 
		int length = movie.length;
		
		mi = new MovieIssue[length];
		
		for (int index = 0; index < length; index++)
		{
			mi[index] = new MovieIssue();
			mi[index].movieid = movie[index].getMovieid();
			mi[index].moviename = movie[index].getMoviename();
			mi[index].moviebanner = movie[index].getMoviebanner();
			mi[index].releasedate  = movie[index].getReleasedate();
			mi[index].rentamount = movie[index].getRentamount();
			mi[index].category = movie[index].getCategory();
			mi[index].copiesavailable = movie[index].getCopiesavailable();

			mi[index].issueid = im[index].getIssueid();
			mi[index].duedate = im[index].getDuedate();
			mi[index].personid = im[index].getPersonid();
			mi[index].issuedate = im[index].getIssuedate();
			mi[index].issuedstatus= im[index].getIssuedstatus();
		}
		return mi;
	}
	public static String convertToString(MovieIssue mi)
	{
		String result = new String();
		
		result = mi.movieid+":#" + mi.moviename+":#" + mi.moviebanner+":#" + new SimpleDateFormat("yyyy-mm-dd").format(mi.releasedate)+":#" + mi.rentamount
		+":#" + mi.category +":#" + mi.copiesavailable+":#" + mi.issueid+":#" + new SimpleDateFormat("yyyy-mm-dd").format(mi.duedate)+":#" + mi.personid+":#" + new SimpleDateFormat("yyyy-mm-dd").format(mi.issuedate)
		+":#" + mi.issuedstatus;
		return result;
	}
	public static MovieIssue[] convertStringToMovieIssueArray(String input[]) throws Exception
	{
		MovieIssue psc[];
		int inputLen = input.length;
		
		psc = new MovieIssue[inputLen];
		
		for (int index = 0; index < inputLen; index++)
		{
			psc[index] = convertToMovieIssue(input[index]);
		}
		return psc;
	}
	public static String[] convertMovieIssueToStringArr(MovieIssue input[])
	{
		String result[];
		int inputLen = input.length;
		
		result = new String[inputLen];
		
		for (int index = 0; index < inputLen; index++)
		{
			result[index] = convertToString(input[index]);
		}
		return result;
	}
}
